﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var uid = txtUsername.Text.Trim();
            var pwd = txtPassword.Text.Trim();
            var sql = string.Format("select * from Users where Username='{0}'and Password='{1}'", uid, pwd);
            var dt = DbHelper.GetDataTable(sql);
            if (dt.Rows.Count > 0)
            {
                var i = dt.Rows[0];
                var IsActived = (bool)i.ItemArray[3];
                var IsDeleted = (bool)i.ItemArray[4];
                var Password = i.ItemArray[2].ToString();
                if (IsDeleted == true)
                {
                    lblComment.Text = "该用户已被删除";
                }
                else
                {
                    if (IsActived == true)
                    {
                        if (pwd == Password)
                        {
                            Response.Redirect("default.aspx");
                        }
                        else
                        {
                            lblComment.Text = "用户名或密码错误，重试";

                        }
                    }
                    else
                    {
                        lblComment.Text = "该用户已被禁用";
                    }
                }
            }
            else
            {
                lblComment.Text = "该用户未注册，请先注册";
            }

        }

    }
}